class Solution {
public:
    ListNode* reverseEvenLengthGroups(ListNode* head) 
    {
        int i = 0;
        ListNode* cur = head;
        ListNode* pre = nullptr;
        while (cur) 
        {
            ++i;
            ListNode* it = cur;
            int len = 0;
            for (; len < i && it; ++len) 
            {
                it = it->next;
            }
            
            if (len & 1) 
            {
                for (int j = 1; j <= len; ++j) 
                {
                    tie(pre, cur) = tuple{cur, cur->next};
                }
            }
            else 
            {
                for (int j = 1; j < len; ++j) 
                {
                    tie(pre->next, cur->next, cur->next->next) = tuple{cur->next, cur->next->next, pre->next};
                }
                tie(pre, cur) = tuple{cur, cur->next};
            }
        }
        return head;
    }
};
/*
原来(1)(2 3)(4 5 6)(7 8 9 10)
反转后(1)(3 2)(4 5 6)(10 9 8 7)
*/
